@extends('layout.default')
@section('title','确认订单')
@section('bodier')



	<!--导入插件-->
	<script type="text/javascript" src="/location/jquery.js"></script>
	<script type="text/javascript" src="/location/area.js"></script>
	<script type="text/javascript" src="/location/location.js"></script>
	<link rel="stylesheet" href="/location/common.css">

<div class="checkout-box">
	
	

    <div class="section section-address">
      <div class="section-header clearfix">
        <h3 class="title">收货地址</h3>

        <div class="more"></div>
      </div>
      <div id="J_addressList" class="section-body clearfix">
        <!-- addresslist begin -->

		@foreach($address as $k=>$v)
        <div  class="address-item J_addressItem" >
          <dl>
            <dt><em class="uname">{{$v->getman}}</em></dt>

            <dd class="utel">{{$v->phone}}</dd>

            <dd class="uaddress attr"  attr="{{$v->sheng}},{{$v->shi}},{{$v->xian}}" >{{$v->sheng}},{{$v->shi}},{{$v->xian}}</dd>
            <dd class="uaddress">{{$v->address}}</dd>
            
          </dl>
          <input type="hidden" class='maid' name='id' value='{{$v->id}}'> 
          <input type="hidden" class='mauserid' name='userid' value='{{$v->userid}}'> 
        </div>
        
		@endforeach
		<script type="text/javascript">
			var id;
			var userid;
      
			// 点击选中并设为默认地址
			$('.J_addressItem').click(function(){
				var abc = $(this);
				id = abc.children('.maid').val();
        userid = abc.children('.mauserid').val();
        
				
				$.ajax({
					url:'/orders/ajax',
					data:{id:id,userid:userid},
					type:'get',
					async:false,
					success:function(data){
						// console.log(data);
						if(data == 1){
							abc.addClass('selected');
							abc.siblings().removeClass('selected');
						}
					},
					error:function(){
						console.log('ajax错误');
					}
				});	
				
			})	
		</script>
		
		
        <div id="J_newAddress" class="address-item address-item-new">
          

          	<!-- Button trigger modal -->
			
			  <i class="iconfont" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"></i> 添加新地址
		
			<!-- Modal -->
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
					<form action="{{url('/orders/insert')}}" method='post'>
					{{csrf_field()}}
				      <div class="modal-body address-edit-box">
				      	<div class="form-section form-section-active">
				            <label>姓名</label>
				            <br>
				            <input type="text" name='getman' required placeholder="收货人姓名" readme='收件人不能为空'><span></span>
				        </div>
				        <br>
				        <div class="form-section">
						    <label>手机号</label>
						    <br>
						    <input type="text" name='phone' placeholder="手机号" required readme='手机号不能为空'><span></span>
						</div>
						<br>
						<div class="form-section form-section-active">
						    <label >详细地址</label>
						    <br>
						    <textarea placeholder="详细地址，路名或街道名称，门牌号" type="text" cols='30px' rows='5px' style='resize:none;' required name='address' readme='详细地址不能为空'></textarea><span></span>
						</div>
						<br>
						<div class="form-section form-section-active">
						    <label>邮政编码</label>
						    <br>
						    <input type="text" name='mailcode' required readme='邮编不能为空'><span></span>
						</div>
						
						<div class="form-section">
						    <label>地址标签</label>
						    
						    <select id="loc_province" required class="" name="sheng" style="width:80px;"></select>
						
							<select id="loc_city" required class="" name="shi" style="width:100px;"></select>
							
							<select id="loc_town" required class="" name="xian" style="width:120px;"></select>
							<span></span>
						    <br>
						    <script type="text/javascript">
								$(document).ready(function() {
									showLocation();
									$('#J_addressList .attr').each(function(){
										var str = $(this).attr('attr');
										var info = getInfo(str);
										$(this).html(info);
									});

									//定义获取城市信息方法
									function getInfo(str){
										//console.log(str);
										//拆分字符串
										var arr = str.split(',');
										// console.log(arr);	
										var ls  = new Location;
										var l = ls.items;
										// console.log(l['0,1,2']['5']);
										var sheng = l['0'][arr[0]];
										var shi = l['0,'+arr[0]][arr[1]];
										var xian = l['0,'+arr[0]+','+arr[1]][arr[2]];
										return sheng+shi+xian;
									}

												
								});
							</script>
						    
						</div>
						<div class="modal-footer">
						
			        	<button class="btn btn-primary">添加</button>
			        	<button class="btn btn-default" data-dismiss="modal">取消</button>
				    </div>
	
			      </div>
			    </form>
			      
			    
			</div>
					
          	

        </div>
      </div>
    </div>

    <div class="section section-options section-payment clearfix">
      <div class="section-header">
        <h3 class="title">支付方式</h3>
      </div>

      <div class="section-body clearfix">
        <ul class="J_optionList options">
          <li data-value="1" class="J_option selected" data-type="pay">在线支付 <span>（支持支付宝、银联、财付通、小米支付等）</span></li>
        </ul>
      </div>
    </div>

    <div class="section section-options section-shipment clearfix">
      <div class="section-header">
        <h3 class="title">配送方式</h3>
      </div>

      <div class="section-body clearfix">
        <ul class="clearfix J_optionList options">
          <li data-value="1" data-amount="0" class="J_option selected" data-type="shipment">快递配送（免运费）</li>
        </ul>

        <div id="J_serviceSelfTip" class="service-self-tip" style="display: none;"></div>
      </div>
    </div>

    <div class="section section-options section-time clearfix">
      <div class="section-header">
        <h3 class="title">配送时间</h3>
      </div>

      <div class="section-body clearfix">
        <ul class="J_optionList options options-list clearfix">
          <!-- besttime start -->

          <li data-value="1" class="J_option" data-type="time">不限送货时间：<span>周一至周日</span></li>

          <li data-value="2" class="J_option" data-type="time">工作日送货：<span>周一至周五</span></li>

          <li data-value="3" class="J_option" data-type="time">双休日、假日送货：<span>周六至周日</span></li><!-- besttime end -->
        </ul>
      </div>
    </div>
	<script type="text/javascript">
		$('.J_option').click(function() {
			$(this).addClass('selected');
			$(this).siblings().removeClass('selected');
		});
	</script>
    
	<br>
  <form action="{{url('/orders/create')}}" method='post' >
  	{{csrf_field()}}
    <div class="section section-goods">
      <div class="section-header clearfix">
        <h3 class="title">商品</h3>

        <div class="more">
          <a href="{{url('/home/cart')}}" data-stat-id="e2cb89a0d7ce0e0b" onclick="">返回购物车<i class="iconfont"></i></a>
        </div>
      </div>

      <div class="section-body">
        <ul id="J_goodsList" class="goods-list">
          @foreach($result as $k => $v)

          <li class="clearfix">
            <div class="col col-img"><img width="30" height="30" src="{{$v[4]}}" /></div>
            
            <div class="col col-name">
              <!-- 商品一句话描述 -->
              <input type="hidden" name='goods_id' value='{{$v[0]}}'>
              <input type="hidden" name='goods_name' value='{{$v[1]}}'>
              <a target="_blank" href="#" data-stat-id="a983b35036d10e6c" onclick="">

                {{$v[1]}}
              </a>
            </div>

            <div class="col col-price">
              {{$v[2]}}(元) x {{$v[3]}}
            </div>

            <div class="col col-status">
              有货
            </div>

            <div class="col col-total">
              <!-- 小计 -->
              {{$v[2] * $v[3]}}(元)
              <input type="hidden" name='price' value='{{$v[2]}}'>
              <input type="hidden" name='num' value='{{$v[3]}}'>
            </div>
          </li>
          
          <li class="clearfix">
            <div class="col col-img"><img width="30" height="30" src="" /></div>

            <div class="col col-name">
              <!-- 套餐名 -->
              <input type="hidden" name='tname' value='{{$v[5]}}'>
              <a target="_blank" href="#" data-stat-id="43894d61926c806e" onclick="">

                {{$v[5]}}
              </a>
            </div>

            <div class="col col-price">
              
            </div>

            <div class="col col-status">
              有货
            </div>

            <div class="col col-total">
              
            </div>
          </li>
        @endforeach
        </ul>
      </div>
    </div>

    <div class="section section-count clearfix">
      <br>
      <div class="fl">
        <div id="J_confirmAddress" class="seleced-address">
         
        </div>

        <div class="big-pro-tip hide J_confirmBigProTip"></div>
      </div>
      <div id="J_moneyBox" class="money-box">
        <ul>
          
          <li class="clearfix"><label>金额合计：</label> <span class="val">{{$total}}元</span></li>

          <li class="clearfix"><label>运费：</label> <span class="val"><i id="J_postageVal">0</i>元</span></li>
          <!-- 总计 -->
          <input type="hidden" name='total' value='{{$total}}'>
          <li class="clearfix total-price"><label>应付总额：</label> <span class="val"><em id="J_totalPrice">{{$total}}</em>元</span></li>
        </ul>
      </div>
    </div>

    <div class="section-bar clearfix">
      
      
        

      <div class="fr">
        <!-- <a id="J_checkoutToPay" class="btn btn-primary"  href=""  onclick="" name="J_checkoutToPay">去结算</a> -->
        <input type="submit" class="btn btn-primary" value='去结算'>
      </div>
    </div>
  </form>
</div>

@endsection